/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bill.model.vo;

import java.util.ArrayList;
import java.util.Date;
import util.Config;
import util.ConstantValues;

/**
 *
 * @author Administrator
 */
public class Order {

    private int id;
    private String code;
    private int iVtid = 1;
    private SaleType saleType = new SaleType();
    private String businessType;
    private Date orderDate;
    private Customer c;
    private Person p = new Person();
    private String remark;
    private ArrayList<OrderDetail> ods = new ArrayList<OrderDetail>();

    public Order() {
        init();
    }

    public void init() {
        this.id = 0;
        this.code = null;
        this.iVtid = 1;
        this.saleType.setId(ConstantValues.SELL_TYPE_Code);
        this.saleType.setName(ConstantValues.SELL_TYPE_NAME);
        this.businessType = ConstantValues.BUSI_TYPE_NAME;
        this.c = Config.getCustomer();
        this.p.setId(ConstantValues.MAKER_CODE);
        this.p.setName(ConstantValues.MAKER_Name);        
        this.p.init();
        this.remark = null;
        ods.clear();
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @return the iVtid
     */
    public int getiVtid() {
        return iVtid;
    }

    /**
     * @param iVtid the iVtid to set
     */
    public void setiVtid(int iVtid) {
        this.iVtid = iVtid;
    }

    /**
     * @return the saleType
     */
    public SaleType getSaleType() {
        return saleType;
    }

    /**
     * @param saleType the saleType to set
     */
    public void setSaleType(SaleType saleType) {
        this.saleType = saleType;
    }

    /**
     * @return the businessType
     */
    public String getBusinessType() {
        return businessType;
    }

    /**
     * @param businessType the businessType to set
     */
    public void setBusinessType(String businessType) {
        this.businessType = businessType;
    }

    /**
     * @return the orderDate
     */
    public Date getOrderDate() {
        return orderDate;
    }

    /**
     * @param orderDate the orderDate to set
     */
    public void setOrderDate(Date orderDate) {
        this.orderDate = orderDate;
    }

    /**
     * @return the c
     */
    public Customer getC() {
        return c;
    }

    /**
     * @param c the c to set
     */
    public void setC(Customer c) {
        this.c = c;
    }

    /**
     * @return the p
     */
    public Person getP() {
        return p;
    }

    /**
     * @param p the p to set
     */
    public void setP(Person p) {
        this.p = p;
    }

    /**
     * @return the remark
     */
    public String getRemark() {
        return remark;
    }

    /**
     * @param remark the remark to set
     */
    public void setRemark(String remark) {
        this.remark = remark;
    }

    /**
     * @return the ods
     */
    public ArrayList<OrderDetail> getOds() {
        return ods;
    }

    /**
     * @param ods the ods to set
     */
    public void setOds(ArrayList<OrderDetail> ods) {
        this.ods = ods;
    }

    public void addOrderDetail(OrderDetail od) {
        ods.add(od);
        updateNo();
    }

    private void updateNo() {
        for (int i = 0; i < ods.size(); i++) {
            OrderDetail od = ods.get(i);
            od.setNo(i + 1);
        }
    }
}
